package com.hexinfo.dmpro.monitor.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.common.base.Page;
import com.hexinfo.dmpro.monitor.model.cm.ServiceState;
import com.hexinfo.dmpro.monitor.model.cm.StateBaseReqModel;
import com.hexinfo.dmpro.monitor.model.cm.StateBaseReqTimeModel;
import com.hexinfo.dmpro.monitor.service.CmStateService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author peng
 * @date 2021/10/14 9:36
 */
@RestController
@RequestMapping("/monitor_api/cmState")
public class CmStateController {

    @Autowired
    private CmStateService cmStateService;

    /**
     * 首页集群状态监控
     * @param model
     * @return
     */
    @GetMapping(value = "/queryClusterState")
    public ResponseEntity<Object> queryClusterState(StateBaseReqModel model) {
        return new ResponseEntity<>(cmStateService.queryClusterState(model), HttpStatus.OK);
    }
    /**
     * 状态监控页面 服务状态监控
     * @param model
     * @return
     */
    @PostMapping(value = "/queryServiceState")
    public ResponseEntity<Object> queryServiceState(@RequestBody StateBaseReqTimeModel model) {
        return new ResponseEntity<>(cmStateService.queryServiceState(model), HttpStatus.OK);
    }
    /**
     * 状态监控页面 角色状态监控
     * @param model
     * @return
     */
    @PostMapping(value = "/queryRoleState")
    public ResponseEntity<Object> queryRoleState(@RequestBody StateBaseReqTimeModel model) {
        return new ResponseEntity<>(cmStateService.queryRoleState(model), HttpStatus.OK);
    }
    /**
     * 状态监控页面 角色检查信息
     * @param model
     * @return
     */
    @PostMapping(value = "/queryRoleChecks")
    public ResponseEntity<Object> queryRoleChecks(@RequestBody StateBaseReqModel model) {
        return new ResponseEntity<>(cmStateService.queryRoleChecks(model), HttpStatus.OK);
    }
    /**
     * 状态监控页面 服务异常次数实时统计信息
     * @param model
     * @return
     */
    @PostMapping(value = "/queryServiceRealTime")
    @AnonymousAccess
    public ResponseEntity<Object> queryServiceRealTime(@RequestBody StateBaseReqModel model) {
        return new ResponseEntity<>(cmStateService.queryServiceRealTime(model), HttpStatus.OK);
    }

    /**
     * 状态监控页面 列表
     * @param serviceState
     * @return
     */
    @GetMapping(value = "/queryServices")
    @AnonymousAccess
    public ResponseEntity<Object> queryServices(Page page, @Param("int")int current, ServiceState serviceState) {
        page.setPageIndex(current-1);
        return new ResponseEntity<>(cmStateService.queryServices(page,serviceState), HttpStatus.OK);
    }

}
